package com.hlft.ancienttinkers;

import com.hlft.ancienttinkers.block.AncientAltarBlock;
import com.mojang.blaze3d.matrix.MatrixStack;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.IRenderTypeBuffer;
import net.minecraft.client.renderer.ItemRenderer;
import net.minecraft.client.renderer.model.IBakedModel;
import net.minecraft.client.renderer.model.ItemCameraTransforms;
import net.minecraft.client.renderer.tileentity.TileEntityRenderer;
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.vector.Vector3f;
import net.minecraftforge.fml.common.Mod;

@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
public class AncientAltarTER extends TileEntityRenderer<AncientAltarBlock.CustomTileEntity> {

	public AncientAltarTER(TileEntityRendererDispatcher rendererDispatcherIn) {
		super(rendererDispatcherIn);
	}

	@Override
	public void render(AncientAltarBlock.CustomTileEntity tile, float partialTicks, MatrixStack matrixStackIn, IRenderTypeBuffer bufferIn, int combinedLightIn, int combinedOverlayIn) {
		ItemRenderer itemRenderer = Minecraft.getInstance().getItemRenderer();
		ItemStack stack = tile.getStackInSlot(0);
		IBakedModel ibakedmodel = itemRenderer.getItemModelWithOverrides(stack, tile.getWorld(), null);
		matrixStackIn.push();
		matrixStackIn.scale(0.5f,0.5f,0.5f);
		matrixStackIn.translate(1, 2.4, 1);
		double tick = System.currentTimeMillis() / 800.0D;
		matrixStackIn.translate(0.0D, Math.sin(tick % (2 * Math.PI)) * 0.065D, 0.0D);
		matrixStackIn.rotate(Vector3f.YP.rotationDegrees((float) ((tick * 40.0D) % 360)));
		itemRenderer.renderItem(stack, ItemCameraTransforms.TransformType.FIXED, true, matrixStackIn, bufferIn, combinedLightIn, combinedOverlayIn, ibakedmodel);
		matrixStackIn.pop();
	}
}
